package com.example.dao.ClassDao;

import com.example.bean.Class;
import com.example.util.DBUtil;
import com.mysql.jdbc.PreparedStatement;

import java.sql.Connection;
import java.sql.SQLException;

public class ClassDeleteDaoImp implements ClassDeleteDao{

    @Override
    public int getClassDelete(Class cl) {
        Connection connection=null;
        PreparedStatement preparedStatement=null;
        try {
            //1.建立连接
            connection = DBUtil.getConnection();
            //2.编写SQL语句
            String sql="delete from c_user where cname=?";
            //3.预处理对象
            preparedStatement = (PreparedStatement) connection.prepareStatement(sql);
            //4.设置占位符
            preparedStatement.setString(1,cl.getCname());
            //5.受影响行数
            int i = preparedStatement.executeUpdate();
            return i;//表示成功
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //6.释放相关的资源
            try {
                DBUtil.closeResource(connection,preparedStatement);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return 0;//表示失败
    }
}
